﻿using System;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;
using BO.Video;
using ChannelVN.Cached.UrlRewrite;
using GUI.Extensions;

namespace GUI.Pages.Video
{
    public partial class VideoDetail : System.Web.UI.Page
    {
        public string VideoDetailData { get; set; }
        public int VideoId { get; set; }
        public int VideoZoneId { get; set; }
        public string ReturnUrl { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            var videoId = RequestExtensions.VideoId;
            if (videoId > 0)
            {
                var dt = VideoBO.GetVideoDetail(videoId);
                if (dt != null && dt.Rows.Count > 0)
                {
                    VideoDetailData = PresentationUtils.ObjectToJson(dt);
                    VideoId = videoId;

                    var r = dt.Rows[0];
                    VideoZoneId = PresentationUtils.Object2Integer(r[SqlConstants.Video.ZoneId].ToString());
                    var objVideoZone = VideoBO.GetVideoZoneDetail(VideoZoneId);
                    ReturnUrl = objVideoZone == null ? "/video.htm" : objVideoZone.Url;

                    var video = String.Format(
                                                "http://static.hosting.vcmedia.vn/players/playerShareFaceBook.swf?key={0}&amp;pname=mediaplayer.swf&amp;domains=facebook",
                                                r[SqlConstants.Video.KeyVideo]);
                    PresentationUtils.AddFacebookVideoMetaData(Page,
                                       PresentationUtils.UrlBuilder.BuildAbsoluteUrl(r[SqlConstants.Video.Url].ToString()),
                                       r[SqlConstants.Video.Name].ToString(),
                                       PresentationUtils.Photo.GetVideoAvatarSource(r[SqlConstants.Video.Avatar].ToString()),
                                       r[SqlConstants.Video.Description].ToString(),
                                       video,
                                       "245",
                                       "400",
                                       "false",
                                       "application/x-shockwave-flash");


                    #region Title/MetaData
                    {
                        PresentationUtils.AddMeta(Page, DefinedConstants.MetaAttributes.Description.Id, DefinedConstants.MetaAttributes.Description.Name, r[SqlConstants.Video.Description].ToString());
                        Page.Header.Title = string.Format("{0} | soha.vn", r[SqlConstants.Video.Name]);
                    }
                    #endregion

                    return;
                }
            }
            _301Redirection.RedirectToFileNotFoundPage();
        }
    }
}